#! /usr/bin/python

import tc
import mapper
import residential

import random

# NEIGHBORHOOD MAPPING
neighborhood = residential.generate_neighborhood("NW")
mapper.map_tc_to_file(neighborhood, "TC Neighborhood", '../FLARE/maps/neighborhood.txt')


# LINKED NEIGHBORHOODS

# caution, testing below!
# Creating a "zone" (linked 5x5 system of neighborhoods)

#create a blank zone template
zone = []
for i in range(0,5):
	zone.append([])
	for j in range(0,5):
		zone[i].append('')

#put NSEW data in it
chance = 70 # an X in 100 chance to appear
for i in range(0, len(zone)):
	for j in range(0, len(zone[i])):

		#check North tile for connection
		if (i-1 >= 0) and ('S' in zone[i-1][j]): #it connects
			zone[i][j] += 'N'
		elif (i-1 >= 0) and (zone[i-1][j] == ''): #unset
			if (random.randint(1,100) < chance):
				zone[i][j] += 'N'
				zone[i-1][j] += 'S' #fixes unset tile
		#check South tile for connection
		if (i+1 < len(zone)) and ('N' in zone[i+1][j]): #it connects
			zone[i][j] += 'S'
		elif (i+1 < len(zone)) and (zone[i+1][j] == ''): #unset
			if (random.randint(1,100) < chance):
				zone[i][j] += 'S'
		#check East tile for connection
		if (j+1 < len(zone)) and ('W' in zone[i][j+1]): #it connects
			zone[i][j] += 'E'
		elif (j+1 < len(zone)) and (zone[i][j+1] == ''): #unset
			if (random.randint(1,100) < chance):
				zone[i][j] += 'E'
		#check West tile for connection
		if (j-1 >= 0) and ('E' in zone[i][j-1]): #it connects
			zone[i][j] += 'W'
		elif (j-1 >= 0) and (zone[i][j-1] == ''): #unset
			if (random.randint(1,100) < chance):
				zone[i][j] += 'W'
				zone[i][j-1] += 'E' #fixes unset tile


# NOW MAP THOSE FILES WITH TELEPORTS TO EACH OTHER
letters = map(chr, range(65, 91))
for i in range(0, len(zone)):
	for j in range(0, len(zone[i])):
		neighborhood = residential.generate_neighborhood(zone[i][j])
		if 'N' in zone[i][j]:
			neighborhood['dimmies'].append('[event]\ntype=teleport\nlocation=59,0,7,1\nintermap=' + letters[i-1] + str(j) + '.txt,62,123')
		if 'S' in zone[i][j]:
			neighborhood['dimmies'].append('[event]\ntype=teleport\nlocation=59,124,7,1\nintermap=' + letters[i+1] + str(j) + '.txt,62,1')
		if 'W' in zone[i][j]:
			neighborhood['dimmies'].append('[event]\ntype=teleport\nlocation=0,59,1,7\nintermap=' + letters[i] + str(j-1) + '.txt,123,62')
		if 'E' in zone[i][j]:
			neighborhood['dimmies'].append('[event]\ntype=teleport\nlocation=124,59,1,7\nintermap=' + letters[i] + str(j+1) + '.txt,1,62')
		filename = '../FLARE/maps/' + letters[i] + str(j) + '.txt'
		mapper.map_tc_to_file(neighborhood, letters[i] + str(j), filename)

from pprint import pprint
pprint(zone) #because there's no good way to show the info yet.

